#!/bin/bash
echo "检查是否安装docker,docker-compose环境"
docker -v
if [ $? -eq  0 ]; then
 echo "检查到Docker已安装!"
else
 echo "安装docker环境..."
 curl https://gitee.com/ligson/centos7script/raw/master/crux-tools/cruxInstall.sh | bash -s init
fi
if [ ! -d "/data/docker/service/prometheus/" ];then
  mkdir -p /data/docker/service/prometheus
  else
  echo "/data/docker/service/prometheus 文件夹已经存在,请手动确认后删除该目录,载执行创建"
  exit
fi
if [ ! -d "/data/docker/service/" ];then
  mkdir -p /data/docker/service
fi
echo "下载prometheus安装包"
cd /data/docker/service
wget https://zwfile.yonyougov.tech/share/crux-tools/conPrometheus/prometheus.tar.gz --no-check-certificate
tar -xvf prometheus.tar.gz
rm -rf prometheus.tar.gz
echo "下载prometheus镜像"
wget https://zwfile.yonyougov.tech/share/crux-tools/conPrometheus/prometheuswar.tar.gz --no-check-certificate
docker load -i prometheuswar.tar.gz
rm -rf prometheuswar.tar.gz
echo "下载consul镜像"
wget https://zwfile.yonyougov.tech/share/crux-tools/conPrometheus/consul.tar.gz --no-check-certificate
docker load -i consul.tar.gz
rm -rf consul.tar.gz
echo "开始下载grafana镜像"
wget https://zwfile.yonyougov.tech/share/crux-tools/conPrometheus/grafana.tar.gz --no-check-certificate
docker load -i grafana.tar.gz
rm -rf grafana.tar.gz
cd prometheus/prometheus/config
sh replaceIp.sh
cd /data/docker/service/prometheus
echo "启动prometheus"
docker network ls | grep mynetwork
if [ $? -eq  0 ]; then
 echo "Docker网络mynetwork已存在!"
else
 echo "创建docker网络"
 docker network create mynetwork
fi
chmod  777 -R /data/docker/service/prometheus/prometheus/data/
docker-compose up -d

